package com.agriculture.repository;

import com.agriculture.entity.GeoParcel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GeoParcelRepository extends JpaRepository<GeoParcel, Integer> {
    
    @Query(value = "SELECT p FROM GeoParcel p WHERE within(:point, p.parcelBoundary) = true")
    List<GeoParcel> findParcelsContainingPoint(@Param("point") org.locationtech.jts.geom.Point point);
    
    @Query(value = "SELECT ST_Area(parcel_boundary) FROM geo_parcel WHERE id = :parcelId", nativeQuery = true)
    Double calculateParcelArea(@Param("parcelId") Integer parcelId);
}